package kr.hkit.androidcomplete02.ch16;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.widget.Toast;

public class MyAlertDialogFragment extends DialogFragment {

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Bundle args = getArguments();
		String title = args.getString("title");
		String message = args.getString("message");
		
		return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message).setPositiveButton("확인", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				doClick(which);
				
			}
		}).setNegativeButton("취소", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				doClick(which);
				
			}
		}).create();
	}

	protected void doClick(int which) {
		//-1 : positive, -3 : negative
		switch(which){
		case -1:
			Toast.makeText(getActivity(), "확인", Toast.LENGTH_SHORT).show();
			break;
		case -3:
			Toast.makeText(getActivity(), "취소", Toast.LENGTH_SHORT).show();
			break;
		}
		
	}
	
}
